package com.huiquan.icd.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.icd.domain.IcdDiseaseSymptom;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class IcdDiseaseSymptomDao extends EnhancedBaseDao<IcdDiseaseSymptom> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "ICD_DISEASE_SYMPTOM.";

	public IcdDiseaseSymptomDao() {
		super(space);
	}


	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveDisSymptomOOrderList() {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_DISEASE_SYMPTOM_O_ORDER", sqlMapClient);
	}
	
	
	public int retrieveTotalPageNo(String ownerId,String type) {
		Map<String, String> param = new HashMap<String, String>();
		param.put("ownerId", ownerId);
		if("s".equals(type)){
			param.put("typeS", type);
		}else{
			param.put("type", type);
		}
		Integer size = (Integer) this.object(space + "RETRIEVE_TOTAL_PAGE_NO", param, sqlMapClient);
		return size == null ? 0 : size;
	}
	@SuppressWarnings("unchecked")
	public Map<String, String> retrievePageOrderVocabulary(Map<String, Object> param) {
		return (Map<String, String>) this.object(space + "RETRIEVE_PAGE_ORDER_VOCABULARY", param, sqlMapClient);
	}
	
	@SuppressWarnings("unchecked")
	public List<IcdDiseaseSymptom> retrieveDiseaseOOrderList(Map<String, Object> param) {
		return (List<IcdDiseaseSymptom>) this.list(space + "RETRIEVE_DISEASE_O_ORDER_LIST", param, sqlMapClient);

	}
	public void updateOrderDiseaseName() {
		update(space + "UPDATE_ORDER_O_DISEASE_NAME", sqlMapClient);
	}
	public void updateFlag(Map<String, Object> param) {
		update(space + "UPDATE_FLAG",param, sqlMapClient);
	}
	public void updateTestFlag(Map<String, Object> param) {
		update(space + "UPDATE_TEST_FLAG",param, sqlMapClient);
	}
	public void updateCheckFlag(Map<String, Object> param) {
		update(space + "UPDATE_CHECK_FLAG",param, sqlMapClient);
	}
	public void updateTestCheckFlag(Map<String, Object> param) {
		update(space + "UPDATE_TEST_CHECK_FLAG",param, sqlMapClient);
	}
	public void updateOrderFlag(Map<String, Object> param) {
		update(space + "UPDATE_ORDER_FLAG",param, sqlMapClient);
	}
	public void updateSymptomOwner() {
		update(space + "UPDATE_SYMPTOM_OWNER", sqlMapClient);
	}
	
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveDisSymptomSOrderList() {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_DISEASE_SYMPTOM_S_ORDER", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveDisSymptomSiOrderList() {
		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_DISEASE_SYMPTOM_SI_ORDER", sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<IcdDiseaseSymptom> retrieveDiseaseByTypeAndDiseaseName(List<String> disease,String type) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("list", disease);
		param.put("type", type);
		return (List<IcdDiseaseSymptom>) this.list(space + "RETRIEVE_DISEASE_BY_TYPE_DISEASE", param, sqlMapClient);

	}
	
	/**
	 * 根据一个Map自定义获取列表
	 * 
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<IcdDiseaseSymptom> retrieveTestList(Map<String, Object> param) {
		return (List<IcdDiseaseSymptom>) this.list(space + "RETRIEVE_TEST_LIST", param, sqlMapClient);
	}
	
	/**
	 * 根据一个Map自定义获取满足条件的数量
	 * 
	 * @param param
	 * @return
	 */
	public int retrieveTestSize(Map<String, Object> param) {
		Integer size = (Integer) this.object(space + "RETRIEVE_TEST_SIZE", param, sqlMapClient);
		return size == null ? 0 : size;
	}
	
	public void  initSTestData(Long uid) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("uid", uid);
		this.insert(space + "INIT_S_TEST_DATA", param, sqlMapClient);
	}
	/**
	 * 根据一个Map自定义获取满足条件的数量
	 * 
	 * @param param
	 * @return
	 */
	public int checkTestWrongSize(Map<String, Object> param) {
		Integer size = (Integer) this.object(space + "CHECK_TEST_DATA_WRONG_SIZE", param, sqlMapClient);
		return size == null ? 0 : size;
	}
	public void deleteTestDataByOwner(long uid,String type) {
		Map<String, Object> param = new HashMap<>();
		param.put("uid", uid);
		param.put("type", type);
		delete(space + "DELETE_TEST_DATA", param, sqlMapClient);
	}
	
	public void updateByNameVocab(String disease,String vocab,String property,Long uid){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("diseaseName", disease);
		param.put("vocab", vocab);
		param.put("property", property);
		param.put("uid", uid);
		this.update(space + "UPDATE_FLAG_BY_DISEASE_VOCAB", param, sqlMapClient);
	}
	public int retrieveUncheckedDisease(){
		Integer countUncheckDisease = (Integer) this.object(space + "RETRIEVE_UNCHECKED_DISEASE", sqlMapClient);
		return countUncheckDisease == null?0:countUncheckDisease;	
	}
}
